package com.tedu.parkinglot.parkCard.service.impl;

import com.tedu.parkinglot.parkCard.mapper.ParkCardMapper;
import com.tedu.parkinglot.parkCard.pojo.dto.ParkCardQuery;
import com.tedu.parkinglot.parkCard.pojo.dto.ParkCardSaveParam;
import com.tedu.parkinglot.parkCard.pojo.entity.ParkCard;
import com.tedu.parkinglot.parkCard.pojo.vo.ParkCardVO;
import com.tedu.parkinglot.parkCard.service.ParkCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;
@Slf4j
@Service
public class ParkCardServiceImpl implements ParkCardService {

    @Autowired
    ParkCardMapper parkCardMapper;

    @Override
    public List<ParkCardVO> selectParkCard(ParkCardQuery parkCardQuery) {
        log.debug("查询车位卡业务参数:{}", parkCardQuery);
        return parkCardMapper.selectParkCard(parkCardQuery);
    }

    @Override
    public void deleteParkCard(Long id) {
        parkCardMapper.deleteParkCard(id);
    }

    @Override
    public void saveParkCard(ParkCardSaveParam param) {
        log.debug("保存车位卡业务参数:{}", param);
        ParkCard parkCard = new ParkCard();
        BeanUtils.copyProperties(param, parkCard);
        parkCard.setUpdateTime(new Date());
        if (parkCard.getId() == null) {
            log.debug("新增车位卡");
            parkCard.setCreateTime(new Date());
            parkCardMapper.insertParkCard(parkCard);
        } else {
            log.debug("修改车位卡");
            parkCardMapper.updateParkCard(parkCard);
        }
    }
}
